﻿using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using QuanLyKhachSan;
using System.Data;
using System.Data.SqlClient;

namespace UnitTest
{
    public class clsTestLoaiPhong : clsTest
    {
        public LoaiPhongDTO loaiPhong;

        public bool Assert_Clauses(DataTable expected, LoaiPhongDTO actual)
        {
            if (expected.Rows.Count > 0)
            {
                DataRow dr = expected.Rows[0];
                Assert.AreEqual((int)dr["maLoaiPhong"], actual.MaLoaiPhong, "I hope the maLoaiPhong is the same");
                Assert.AreEqual(dr["tenLoaiPhong"], actual.TenLoaiPhong, "TenLoaiPhong not the same");
                Assert.AreEqual(float.Parse(dr["donGia"].ToString()), actual.DonGia, "donGia not the same");
                Assert.AreEqual((int)dr["danhDau"], actual.DanhDau, "danhDau not the same");
                return true;
            }
            
            return false;
        }
        [Test]
        public void TestInsert()
        {
            LoaiPhongDTO lp = new LoaiPhongDTO();
            lp.TenLoaiPhong = "Loại Phòng test2";
            lp.DonGia = 12345;

            bool kq = LoaiPhongDAO.Insert(lp);

            Dictionary<string, object> para = new Dictionary<string, object>();
            para.Add("tenLoaiPhong", lp.TenLoaiPhong);
            para.Add("donGia", lp.DonGia);

            expectedData = select_DataTable("LoaiPhong",para);
            if (expectedData.Rows.Count == 0)
            {
                Assert.IsFalse(kq);
            }
            else
            {
                Assert.GreaterOrEqual(expectedData.Rows.Count, 1, "Cần Insert xuống CSDL");
                Assert.IsTrue(kq);
                Assert.AreEqual(expectedData.Rows[0]["tenLoaiPhong"], lp.TenLoaiPhong, "TenLoaiPhong not the same");
                Assert.AreEqual(float.Parse(expectedData.Rows[0]["donGia"].ToString()), lp.DonGia, "donGia not the same");
            }
        }
        [Test]
        public void TestUpdateLoaiPhong()
        {
            LoaiPhongDTO lp = new LoaiPhongDTO();
            lp.MaLoaiPhong = 1;
            lp.TenLoaiPhong = "A1 Test";
            lp.DonGia = float.Parse("154000");
            lp.DanhDau = 0;

            bool kq = LoaiPhongDAO.Update(lp);

            Dictionary<string, object> para = new Dictionary<string, object>();
            para.Add("maLoaiPhong", lp.MaLoaiPhong);

            expectedData = select_DataTable("LoaiPhong",para);
            if (expectedData.Rows.Count == 0)
            {
                Assert.IsFalse(kq);
            }
            else
            {
                Assert_Clauses(expectedData, lp);
                Assert.IsTrue(kq);
            }
        }
    }
}
